<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../assets/css/layui.css"/>
	<link rel="stylesheet" type="text/css" href="../../assets/css/view.css"/>
</head>
<body class="layui-view-body">
 	<div class="layui-content">
		<div class="layui-row">
			<div class="layui-card">
				<div class="layui-card-header">录入快递员信息</div>
				<form id="form" class="layui-form layui-card-body">
					<div class="layui-form-item">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-block">
							<input type="text" name="name" required lay-verify="required" placeholder="请输入快递员姓名" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电话号</label>
						<div class="layui-input-block">
							<input type="tel" name="phoneNumber" required lay-verify="required" placeholder="请输入快递员电话号" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">身份证号</label>
						<div class="layui-input-block">
							<input type="text" name="idNumber" required lay-verify="required" placeholder="请输入快递员身份证号" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="password" required lay-verify="required" placeholder="请输入快递员登录密码" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
    <script src="../../assets/layui.all.js"></script>
	<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
	<script>
		var form = layui.form,
				layer = layui.layer;
	</script>
	<script>
		$(function(){
			$("#form").submit(function(){
				var phonegrep = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
				var windowId = layer.load();
				var name = $("input:eq(0)").val();
				var phoneNumber = $("input:eq(1)").val();
				var idNumber = $("input:eq(2)").val();
				var password = $("input:eq(3)").val();
				if (phoneNumber.length!=11||!phonegrep.test(phoneNumber)||idNumber.length != 18||password.length<=8){
					if (phoneNumber.length!=11||!phonegrep.test(phoneNumber)) {
						layer.msg("手机号格式错误");
						$("input:eq(1)").css("color", "red");
						layer.close(windowId);
					}else {
						$("input:eq(1)").css("color", "black");
					}
					if (idNumber.length != 18||password.length<=8){
						if (password.length<=8){
							layer.msg("密码长度不够");
							$("input:eq(3)").css("color","red");
							layer.close(windowId);
						}else {
							$("input:eq(3)").css("color", "black");
						}
						if (idNumber.length != 18){
							layer.msg("身份证格式错误");
							$("input:eq(2)").css("color","red");
							layer.close(windowId);
						}else {
							$("input:eq(2)").css("color", "black");
						}
					}
					return false;
				}
				$.post("/courier/add.do",{
					name:name,
					phoneNumber:phoneNumber,
					idNumber:idNumber,
					password:password
				},function (data){
					layer.close(windowId);
					layer.msg(data.result);
					if (data.status==0){
						$("input").val("");
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>
